package com.example.demo4.service.impl;

import com.example.demo4.entity.Fruit;
import com.example.demo4.service.AbstractStrategy;

import java.math.BigDecimal;
import java.util.List;
/**
 * 策略模式 上下文
 */
public class CashContext {

    private AbstractStrategy cs;
    public CashContext(String type){
        switch (type){
            case "正常收费":
                cs=new PriceNormal();
                break;
            case "满100减10":
                cs=new PriceFullDecrement(new BigDecimal(100), new BigDecimal(10));
                break;
            case "打折":
                cs=new PriceDiscount();
                break;
        }

    }
    public BigDecimal acceptCash(List<Fruit> fruits){
        return cs.acceptCash(fruits);
    }

}
